package com.onpositive.wiki3.db.impl;

import java.io.IOException;
import java.io.RandomAccessFile;

import com.onpositive.data.IReadableObjectCollection;
import com.onpositive.data.diskstorage.AbstractObjectCollection;
import com.onpositive.data.serializer.readers.ObjectCollectionReader;
import com.onpositive.data.serializer.readers.RandomAccessFileAccess;
import com.onpositive.datamap.IDataPropertyValue;
import com.onpositive.datamap.core.IDataObject;
import com.onpositive.datamap.core.IDataProperty;
import com.onpositive.datamap.core.impl.DataCollection;
import com.onpositive.datamap.values.impl.PlainTextTokenAcceptor;
import com.onpositive.wiki3.db.SimpleReconciler;
import com.onpositive.wiki3.db.SimpleValueModel;

public class MergerTests {

	public static void main(String[] args) {
		final WikiDBImpl wikiDBImpl = new WikiDBImpl("C:/work/content");
		SimpleReconciler ss;
		try {
			ss = new SimpleReconciler(wikiDBImpl);
			// System.out.println(ss.getReconciledType("Anarchism"));
			// System.out.println(ss.getReconciledType("Anticommunism"));
			// System.out.println(ss.getReconciledType("Boris_Berezovsky_(businessman)","Navalny"));
			// System.out.println(ss.getReconciledType("Berezovski","Hodorkovsky"));
			// System.out.println(ss.getReconciledType("Ferrari","Maserati"));
			// System.out.println(ss.getReconciledType("Putin","Yeltsin","Gorbachev"));
			// System.out.println(ss.getReconciledType("Russia",
			// "Serbia","Poland"));
			// System.out.println(ss.getReconciledType("Kosovo",
			// "Abhasia"));
			// System.out.println(ss.getReconciledType("Kosovo",
			// "Serbia"));
			// System.out.println(ss.getReconciledType("Hamas",
			// "Taliban"));
			// System.out.println(ss.getReconciledType("Heinkel", "Toshiba",
			// "Toyota"));
			// System.out.println(ss.getReconciledType("Spider","Fish"));
			// System.out.println(ss.getReconciledType("T-34","Su-27","T-90"));
			// System.out.println(ss.getReconciledType("T-34","T-90"));
			// System.out.println(ss.getReconciledType("spies","actors"));
			// System.out.println(ss.getReconciledType("Kill_Bill","Iron_Sky"));
			// System.out.println(ss.getReconciledType("iphone","galaxy tab"));
			System.out.println(ss.getReconciledType("floatplace", "seaplane"));
			IReadableObjectCollection<?>[] collection = new ObjectCollectionReader()
					.getCollection(new RandomAccessFileAccess(
							new RandomAccessFile(
									"C:\\work\\android\\com.onpositive.fighterspedia\\assets\\serialized.jpg",
									"r")));
			DataCollection c = new DataCollection((AbstractObjectCollection) collection[0], "a", null);
			IDataProperty[] properties = c.getProperties();
			for (IDataProperty p : properties) {
				if (p.simpleType().equals("value-sequence")) {
					
					final CountingVocabalary vs = new CountingVocabalary();
					for (int a = 0; a < c.getCount(); a++) {
						IDataObject object = c.getObject(a);
						IDataPropertyValue value = p.getValue(object);
						PlainTextTokenAcceptor token = new PlainTextTokenAcceptor() {
							@Override
							public void acceptExternalIdentifier(String text,
									String url, String propertyid) {
								if (url.equals("engine")){
									System.out.println("A");
								}
								if (url.length() > 0) {
									vs.add(url);
								}
							}

							@Override
							public void acceptInternalIdentifier(String text,
									String number, String propertyId) {
								if (text.length() > 0) {
									vs.add(text);
									super.acceptInternalIdentifier(text,
											number, propertyId);
								}
							}
						};
						if (value != null) {
							value.render(token);
						}

					}
					// if (!str.isEmpty()){
					SimpleValueModel reconciledType = ss.getReconciledTypeSoft(vs);
					if (reconciledType.toString().length()>0){
					System.out.println(p.id()+":"+ reconciledType);
					}
					// }

				}
			}
			// System.out.println(ss.getReconciledType("VAZ 2101","VAZ 2103"));
			// System.out.println(ss.getReconciledType("Toyota Vista","Ford Escape Hybrid","VAZ 2101"));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}
}
